/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 */

#ifndef _AT_PARSER_H_
#define _AT_PARSER_H_

#include <at_common.h>

/* Delimiter */
#define AT_RECV_END_CHAR          '\n'
#define AT_RECV_FAIL_POSTFIX    "ERROR"
#define AT_SEND_DELIMITER       "\r\n"


typedef struct {
    char *reply_prefix;
    char *reply_fail_postfix;
} atcmd_config_t;

typedef void (*at_recv_cb)(void *arg, char *buf, int buflen);

/**
 * initialization
 * in above macro
 */
bool at_parser_init(void);
bool at_parser_deinit(void);

/**
 * at send (format: command + delimiter + data) and wait reply
 *
 * @param cmd at command sending buf. MUST not be NULL.
 * @param cmdlen at command length.
 * @param delimiter whether sending delimiter, usually value is true
 * @param prefix   Receiving a message containing prefix is a valid reply
 * @param fail_prefix Receiving a message containing fail_prefix is a error reply
 * @param replybuf reply buffer. MUST not be NULL.
 * @param replysize[in,out] reply buffer size
 * @param timeout 
 */
bool at_send_wait_reply( const char *cmd, uint16_t cmdlen,bool delimiter,
                        char *prefix,char *fail_prefix,
                        char *replybuf, int *replysize,
                        uint16_t timeout);

/**
 * at send (format: data + delimiter) and does not wait reply
 *
 * @param data sending buffer.
 * @param datalen sending length.
 * @param delimiter whether sending delimiter, usually value is false
 * @param timeout
 */
bool at_send_no_reply(const char *data, int datalen, bool delimiter,uint32_t timeout);




/**
 * at register callback for recv
 *
 * @param prefix interested string. Must not be NULL.
 * @param cb callback handle function. Must not be NULL.
 * @param arg callback handle function args. NULL if not used.
 */
bool at_register_callback(const char *prefix, at_recv_cb cb, void *arg);

#endif

